package com.bw.base.mvvm

import android.os.Bundle
import android.view.LayoutInflater
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.ViewDataBinding
import androidx.lifecycle.ViewModelProvider
import java.lang.reflect.ParameterizedType

abstract class BaseViewActivity <VDB:ViewDataBinding>:AppCompatActivity(){

    //获取类的泛型参数列表
   private val type by lazy { (javaClass.genericSuperclass as ParameterizedType).actualTypeArguments }
    //获取binding对象
    val binding by lazy {
     val clazz=   type[0] as Class<VDB>
        val method = clazz.getMethod("inflate", LayoutInflater::class.java)
        method.invoke(null,layoutInflater)as VDB

    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(binding.root)

        initView()
        intiData()

    }

    abstract fun initView()
    abstract fun intiData()
}